Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container GATs, improve traits #541

Merged
merged 3 commits into from
Mar 19, 2024

Conversation

antiguru
Copy link
Member

@antiguru antiguru commented Feb 4, 2024

Cleanup the Container::Item type, move it to PushPartitioned and make it a GAT. Similarly, split the Map trait in two (Map, MapInPlace) and support GATs in the Map trait.

This has the benefit that Timely becomes less opinionated about the interface provided by containers, for example by allowing non-owned data when calling stream.map.

Signed-off-by: Moritz Hoffmann <[email protected]>
@antiguru antiguru changed the title Container GATs, improve Map trait Container GATs, improve traits Feb 18, 2024
@antiguru
Copy link
Member Author

antiguru commented Mar 1, 2024

I reworked the PR to only contain a minimum of changes. This compiles with differential once applying the following patch:

diff --git a/src/collection.rs b/src/collection.rs
index f2daf8ad..20cab0d2 100644
--- a/src/collection.rs
+++ b/src/collection.rs
@@ -416,10 +416,10 @@ impl<G: Scope, D: Data, R: Semigroup> Collection<G, D, R> where G::Timestamp: Da
     ///          .inspect_batch(|t,xs| println!("errors @ {:?}: {:?}", t, xs));
     /// });
     /// ```
-    pub fn inspect_batch<F>(&self, func: F) -> Collection<G, D, R>
+    pub fn inspect_batch<F>(&self, mut func: F) -> Collection<G, D, R>
     where F: FnMut(&G::Timestamp, &[(D, G::Timestamp, R)])+'static {
         self.inner
-            .inspect_batch(func)
+            .inspect_batch(move |time, batch| func(time, &batch[..]))
             .as_collection()
     }
     /// Attaches a timely dataflow probe to the output of a Collection.
(

Containers are generic over their contents, and over reading and draining.

Signed-off-by: Moritz Hoffmann <[email protected]>
Signed-off-by: Moritz Hoffmann <[email protected]>
Copy link
Member

@frankmcsherry frankmcsherry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I propose we merge this and start to see what it leads to downstream.

Comment on lines +30 to +31
/// of all pieces must be equal to the length of the original container. When combining
/// containers, the length of the result must be the sum of the individual parts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point we do not know what it means to "combine a container".

type DrainIter<'a>: Iterator<Item=Self::Item<'a>>;

/// Returns an iterator that drains the contents of this container.
/// Drain leaves the container in an undefined state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could/should say more about what "undefined state" means. Perhaps "it is an error to do anything other than clear or drop" or " unless you are certain the type is FOO".

F: FnMut(usize, &mut Self);
}

impl<T: Clone + 'static> PushPartitioned for Vec<T> {
impl<T: PushContainer + 'static> PushPartitioned for T where for<'a> T::Item<'a>: PushInto<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussion: might we want to make push_partitioned into a free function generic in a T1: Container and T2: PushContainer, reading from the first and writing in to the second?

@@ -7,7 +7,7 @@ use crate::dataflow::operators::generic::operator::Operator;
use crate::dataflow::{Scope, StreamCore};

/// Exchange records between workers.
pub trait Exchange<D> {
pub trait Exchange<C: PushPartitioned> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From discussion: This could be C: Container because it is only used to bind C::Item<'a>.

@frankmcsherry frankmcsherry merged commit ded1a39 into TimelyDataflow:master Mar 19, 2024
1 check passed
@antiguru antiguru deleted the container_gat branch March 19, 2024 18:22
@github-actions github-actions bot mentioned this pull request Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants